package siruna.WE.DeviceDependent;

import java.io.FileDescriptor;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.zip.ZipEntry;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import siruna.WE.DeviceDependent.rendering.WidgetView;
import siruna.WE.core.events.Event;
import siruna.WE.core.model.VisualBlock;
import siruna.WE.core.model.VisualBlocks.ButtonImpl;
import siruna.WE.core.model.VisualBlocks.ImageImpl;
import siruna.WE.core.model.VisualBlocks.LabelImpl;

public class AndroidWidgetFactory {

	private WidgetView widgetView;

	public AndroidWidgetFactory(WidgetView widgetView) {
		this.widgetView = widgetView;

	}

	public View getAndroidView(final VisualBlock visualBlock) {
		View v = null;

		final HashMap<String, String> attributes = visualBlock.getAttributes();
		LayoutParams wrapcontent = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);

		System.out.println(visualBlock.getClass().getSimpleName());

		String klasse = visualBlock.getClass().getSimpleName();
		int sub = klasse.length() - 4;

		Class calc;

		try {
			calc = Class.forName("siruna.WE.DeviceDependent.AndroidViews."
					+ klasse.substring(0, sub) + "Renderer");

			Constructor<View> con = calc.getConstructor(Context.class,
					VisualBlock.class);

			v = (View) con.newInstance(widgetView, visualBlock);

		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		return v;

		/*
		 * if (visualBlock.getAttributes().containsKey("visible")) { if
		 * (visualBlock.getAttributes().get("visible").equals("false")) {
		 * v.setVisibility(v.GONE); } }
		 */

	}
}
